Skip to content

refactor(cuda.core): name the states of a ReleasingHandleRegistry entry - #3547

Merged
rparolin merged 4 commits into
mainfrom
ipc-readability/1-registry-states
Nov 25, 2026
Merged

rparolin merged 4 commits into
mainfrom
ipc-readability/1-registry-states

Conversation

@rparolin

@rparolin rparolin commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Readability follow-up to #3511. Part 1 of 4 (stack: #3547 → #3548 → #3549 → #3552). No behavior change on any path that exists today.

ReleasingHandleRegistry::get_or_create() told "release in flight" apart from "live owner" by whether a weak_ptr had expired, inside a hand-written wait loop.

  • Name the three states: Vacant, Live, Releasing.
  • Wait on a predicate instead of the loop.
  • find() returns the state and the owner together in a Lookup struct.
  • find() takes the caller's unique_lock and raises an internal error unless it is held on this registry's mutex. The rule was a comment before.

Insert-before-create and release() are untouched.

Testing

  • Top of the stack: the full cuda_core test suite passes on an RTX 5880 Ada (cu13), except test_object_code_load_rdc*, which cannot build its fixture on my machine (system nvcc rejects the environment's gcc).
  • clang-tidy clean, pre-commit clean.
  • No new tests: the existing tests cover this path.

PLC Local Security Evidence (Advisory)

Local advisory checks only, run over the whole stack. Not release-gate results.

Check Status Tool Details
Secrets SKIP Pulse Secret Scanner registry login failed locally; the repo trufflehog pre-commit hook passed
SAST PASS Semgrep 0 findings (local advisory)
Dependencies N/A - no manifests or lockfiles changed
License N/A - no dependencies changed
Container N/A - no container changed

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

🤖 Generated with Claude Code

get_or_create() told "release in flight" apart from "live" by whether an
entry's weak_ptr had expired, inside a hand-written wait loop. Name the
three states (Vacant, Live, Releasing) and wait on a predicate.

No behavior change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@rparolin
rparolin added this pull request to stack #3550 November 24, 2026 16:14
@rparolin rparolin changed the title ipc readability/1 registry states refactor(cuda.core): name the states of a ReleasingHandleRegistry entry Nov 24, 2026
@rparolin rparolin added this to the cuda.core 1.4.0 milestone Nov 24, 2026
@rparolin rparolin added the cuda.core Everything related to the cuda.core module label Nov 24, 2026
@rparolin rparolin self-assigned this Nov 24, 2026
find() returned the state and filled the owner through an out
parameter. Return both in a Lookup struct.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
find() said "requires mutex_" in a comment. It now takes the caller's
unique_lock and raises an internal error unless that lock is held and
locks this registry's mutex.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
@rparolin
rparolin marked this pull request as ready for review November 24, 2026 16:46
@rparolin rparolin added the enhancement Any code-related improvements label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of shared runtime resources during release. Requests encountering a resource being released now wait and retry, while active resources can still be reused. When a resource is no longer available, the system can proceed with creating one, helping prevent conflicting access and supporting more consistent resource availability.

The registry lookup now distinguishes vacant, live, and releasing entries. get_or_create waits while an entry is releasing, returns a live owner, or creates an owner for a vacant key. The lookup helper checks lock ownership and throws std::runtime_error if the lock is invalid.

Changes: Registry lookup and creation

Layer / File(s) Summary
Classify entries and coordinate creation
cuda_core/cuda/core/_cpp/rt/internal.hpp
find classifies entries as vacant, live, or releasing and validates lock ownership. get_or_create waits only while an entry is releasing, returns a live owner, or creates an owner when the key is vacant.

Possibly related PRs

  • NVIDIA/cuda-python#3272: Adds clang-tidy to the cuda-core build; a follow-up commit for this PR reports that the Windows build's clang-tidy check rejects find().

Suggested reviewers: juenglin

Change: Refactor

Merge Risk: Minimal · up to 1f80e

This refactor names the registry entry states and replaces a hand-written wait loop with a predicate wait. Existing behavior is preserved and no concrete defect was found, so the change is ready to merge.

Security architecture risk: Minimal · up to 1f80e

The change makes resource ownership states explicit without changing when an IPC import reuses an owner, waits for cleanup, or creates a new owner. No new access path or loss of cleanup protection was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The confirmed downstream scope includes both IPC ownership paths within the importing process. Their existing CUDA driver import calls and arguments are unchanged; the registry refactor adds no route to those calls.

Trust Boundaries and Controls

  • observed — The private lookup guard checks mutex ownership, not import authorization. The inspected call path constructs the lock internally, and the condition-variable predicate evaluates with that lock held, so the new guard does not add an input-dependent failure path.

Resilience and Maintainability Implications

  • observed — Creation stays serialized under the registry mutex. A throwing factory or an empty result erases the provisional entry before unlocking, so failed creation does not leave a stale entry to block a later import.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clang (23.1.4)

cuda_core/cuda/core/_cpp/rt/internal.hpp

Clang-Tidy produced no recognizable diagnostics; analysis is incomplete

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b22104c and 1f80ea2.

Files selected for processing: 1

  • cuda_core/cuda/core/_cpp/rt/internal.hpp

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 5 remain after this review.

clang-tidy's modernize-use-nodiscard rejects find() in the Windows
build.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Rob Parolin <rparolin@nvidia.com>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

[[nodiscard]] Lookup
find(const std::unique_lock<std::mutex> &held, const Key &key) const
{
if (!held.owns_lock() || held.mutex() != &mutex_) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems unnecessary. find requiring the lock as parameter is sufficient.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That check is there b/c you can pass a reference to a mutex into a function. That does mean the thread has acquired the lock. That's what we are checking there.

@rparolin
rparolin merged commit cc36ad0 into main Nov 25, 2026
122 checks passed
@rparolin
rparolin deleted the ipc-readability/1-registry-states branch November 25, 2026 22:33
github-actions Bot pushed a commit that referenced this pull request Nov 26, 2026
Removed preview folders for the following PRs:
- PR #3521
- PR #3526
- PR #3547
- PR #3548
- PR #3549
- PR #3552
- PR #3589
- PR #3590
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module enhancement Any code-related improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants